home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v9n03.arc / CHKBOOT.ASM < prev    next >
Assembly Source File  |  1990-01-12  |  62KB  |  1,099 lines

  1.          PAGE  60,132
  2.          TITLE CHKboot - High performance boot sector checker
  3. ;        SUBTTL  General program description and use of common storage
  4. ; ----------------------------------------------------------------------------;
  5. ;        CHKboot - check DOS boot record and partition table boot for changes.;
  6. ; ----------------------------------------------------------------------------;
  7. ;   CHKBOOT 1.0 ■ PCDATA TOOLKIT Copyright (c) 1990 Ziff Communications Co.   ;
  8. ;                       PC Magazine ■ Wolfgang Stiller                        ;
  9. ;                                                                             ;
  10. ;-----------------------------------------------------------------------------;
  11.  
  12. ;Purpose:                                                                     ;
  13. ;CHKBOOT checks the integrity of DOS boot sectors and hard disk               ;
  14. ;partition tables (sectors).  On first execution, or with the "/I"            ;
  15. ;parameter, CHKBOOT writes check values to the parameter file and             ;
  16. ;creates reload files for the boot and partition sectors.  All files          ;
  17. ;written contain self check information.  CHKBOOT subsequently will           ;
  18. ;check the DOS boot record and/or the partition sector for any changes        ;
  19. ;by using information recorded on the parameter file.                         ;
  20. ;                                                                             ;
  21. ; ----------------------------------------------------------------------------;
  22. ;Format:                                                                      ;
  23. ;                                                                             ;
  24. ;CHKBOOT [filespec] [/B] [/H] [/I] [/P] [/2]                                  ;
  25. ;                                                                             ;
  26. ;"filespec" is optional file specification for the parameter file. If not     ;
  27. ;      specified, "CHKBOOT.PRM" will be used as the parameter file.           ;
  28. ;"/H"  Presents extensive detailed help information.                          ;
  29. ;"/B"  Checks boot record on current DOS disk for any changes.                ;
  30. ;"/P"  Checks partition sector on first physical hard disk for any changes.   ;
  31. ;"/2"  Checks partition sector on second physical hard disk.                  ;
  32. ;       /P and /2 may not be specified together.                              ;
  33. ;"/I"  Force initialization. Attempts read of current boot sector and         ;
  34. ;      partition sector on 1st hard drive (Include /2 for 2nd partition       ;
  35. ;      sector).  CHKBOOT then writes the parameter file so that any           ;
  36. ;      changes to these sectors can be detected on subsequent                 ;
  37. ;      executions. The boot and partition sectors are copied to files         ;
  38. ;      @@BOOT.SCT and @@PARTIT.SCT for LODboot reload.                        ;
  39. ;                                                                             ;
  40. ;      At least one of the parameters, /B /P /2 or /I must be entered.        ;
  41. ;      If /I is entered then /B and /P are ignored if entered (/2 is          ;
  42. ;      honored).                                                              ;
  43. ;                                                                             ;
  44. ;Note, If the parameter file does not exist, then CHKBOOT will                ;
  45. ;      automatically initialize and create the file.                          ;
  46. ;                                                                             ;
  47. ;Example: "CHKBOOT /B /F"  will read both the DOS boot sector and the         ;
  48. ;         partition sector on the 1st hard drive and compare the              ;
  49. ;         cryptographic checksums from a prior execution.                     ;
  50. ;-----------------------------------------------------------------------------;
  51. ;Remarks:                                                                     ;
  52. ;  It is safest to keep CHKBOOT and all its files off-line on a floppy.       ;
  53. ;  This floppy should be bootable (created with FORMAT d:/S).  In order       ;
  54. ;  to check hard disk partition sectors, CHKBOOT can be executed              ;
  55. ;  directly from anywhere. To check a DOS boot sector, you must be            ;
  56. ;  logged on to the DOS drive you wish to check.  If for example, your        ;
  57. ;  floppy is drive A, and C is your default drive, then                       ;
  58. ;                  A:CHKBOOT A:CHKBOOT.PRM/B/P                                ;
  59. ;  will cause the program and the parameter file (CHKBOOT.PRM) to both        ;
  60. ;  be utilized from floppy. The DOS boot sector from drive C and the          ;
  61. ;  hard disk partition sector from the first physical disk will be            ;
  62. ;  checked.                                                                   ;
  63. ;                                                                             ;
  64. ;  All files created by CHKBOOT contain validity check data embedded.         ;
  65. ;  Any change to any of the files will be detected whenever the file is       ;
  66. ;  processed. If CHKBOOT finds corruption to either the parameter file        ;
  67. ;  or the sectors it is checking, it will produce an error message, beep,     ;
  68. ;  and force the user to acknowledge with a key press.  Other serious         ;
  69. ;  errors detected are also handled in this way.                              ;
  70. ;                                                                             ;
  71. ;  The following DOS errorlevels will be returned on termination.             ;
  72. ;                                                                             ;
  73. ; 00 - Compare of boot and/or partition records successful.                   ;
  74. ; 02 - Compare of boot sector failed.                                         ;
  75. ; 04 - Compare of partition sector failed.                                    ;
  76. ; 06 - Compare of both boot and partition boot sectors failed.                ;
  77. ; 16 - Initialization occurred. No compare done.                              ;
  78. ; 32 - Corruption of the parameter file detected (CHKBOOT.PRM).               ;
  79. ; 64 - Program failure (usually due to disk problems or lack of space on disk);
  80. ;128 - Syntax error on invoking CHKBOOT.                                      ;
  81. ;                                                                             ;
  82. ;-----------------------------------------------------------------------------;
  83.  
  84. ;---------------------------------------------------------------;
  85. ; Constants:                                                    ;
  86. ;---------------------------------------------------------------;
  87. BOX          EQU    254                   ;Small box character code
  88. CR           EQU    0Dh
  89. LF           EQU    0Ah
  90. CRLF         EQU    0A0Dh                 ;Carriage return line feed.
  91. Boot_type    EQU    0FFh                  ;Indicator of a boot sector (.PRM)
  92. Part_type    EQU    055h                  ;Indicator of a partition sector(.PRM)
  93. ; Double line drawing character definitions
  94. Horizontal   EQU    205                   ;Horizontal double line
  95. Vertical     EQU    186                   ;Vertical double line
  96. UPRT_corner  EQU    187                   ;Upper righthand corner
  97. UPLT_corner  EQU    201                   ;Upper lefthand corner
  98. LWLT_corner  EQU    200                   ;Lower lefthand corner
  99. LWRT_corner  EQU    188                   ;Lower righthand corner
  100.  
  101. CSEG    SEGMENT
  102.         ASSUME  CS:CSEG, DS:CSEG, ES:CSEG, SS:CSEG
  103.  
  104.         SUBTTL  Main program
  105. ;******************************************************************************;
  106. ;**   Main program begins here -CHKBOOT-                                     **;
  107. ;******************************************************************************;
  108.         ORG     100H                      ; THIS IS A COM TYPE PROGRAM
  109. CHKBOOT:
  110.         CALL    Parse_parms               ;Parse cmdline paramters
  111.  
  112.         MOV     DX, offset Header_Msg     ;Put out title display
  113.         MOV     AH,09H                    ;DOS display string function
  114.         INT     21H
  115.  
  116. ; Check system sector size
  117.         MOV     AH,36h                    ;Check sector size and free space
  118.         XOR     DL,DL                     ;Check current disk (DL=0 is current)
  119.         INT     21h
  120.         MOV     Sector_Size,CX            ;Save # of bytes per sector
  121.         CMP     CX,512                    ;Is this a standard size sector
  122.         JE      Continue_main_process     ;  If so, continue
  123.         MOV     DX, OFFSET Non_STD_Msg    ;  Else put out message warning user
  124.         MOV     AH,09h                    ;  DOS display function
  125.         INT     21h
  126.  
  127. Continue_main_process:
  128.         XOR     BP,BP                     ;Zero out highest error level code
  129.         CMP     Initialize_Mode,'Y'       ;Has init mode been requested?
  130.         JE      Initialize_all_files      ;  If so, then initialize this program
  131.         CALL    Open_and_Read_PARM_file   ;Open and verify existance of parmfile
  132.                                           ; If open fails, set initialize flag
  133.         CMP     Initialize_Mode,'Y'       ;Check again if INIT is requested...
  134.         JE      Initialize_all_files      ;  If so, then initialize this program
  135.         CALL    Validate_Parm_File        ;Make sure its a valid parm file
  136.         CMP     Boot_wanted,'Y'           ;Does user want BOOT rec checked?
  137.         JNE     No_Boot                   ;  If not skip checking the boot rec
  138.         CALL    Read_Boot_Sector          ;Do actual read of sector 0 (DOS)
  139. ;  --------- Calculate cryptographic check/XOR sums for disk sector -----------
  140.         MOV     SI,offset BUFFER          ;Point SI to buffer containing sector
  141.         MOV     CX,Sector_Size            ;Process all bytes in a sector
  142.         CALL    Calc_Sums                 ;Calculate CHK and XOR sums
  143. ; On return:                DI - Contains checksum for this file
  144. ;                           DX - XOR sum
  145. ; -----------------------------------------------------------------------------
  146.         CALL    Compare_Boot_Sums         ;See if any changes to the sector
  147. NO_BOOT:
  148.         CMP     Partition_wanted,'Y'      ;Does user want Partition  checked?
  149.         JNE     End_Execution             ;  If not skip checking the Partition
  150.         CALL    Read_Part_Sector          ;Do actual read of sector 0 (BIOS)
  151. ;  --------- Calculate cryptographic check/XOR sums for disk sector -----------
  152.         MOV     SI,offset BUFFER          ;Point SI to buffer containing sector
  153.         MOV     CX,Sector_Size            ;Process all bytes in a sector
  154.         CALL    Calc_Sums                 ;Calculate CHK and XOR sums
  155. ; On return:                DI - Contains checksum for this file
  156. ;                           DX - XOR sum
  157. ; -----------------------------------------------------------------------------
  158.         CALL    Compare_Part_Sums         ;Any changes to partition sector?
  159. End_Execution:                            ;Successful termination of program
  160.         MOV     AX,BP                     ;BP contains highest error level
  161.         MOV     AH,4Ch                    ;DOS terminate with errorlevel funct
  162.         INT     21h
  163.  
  164.  
  165. ;---------------------------------------------------------------------;
  166. ; Initialize all files-initialize this program - writing "PARM_File"  ;
  167. ;---------------------------------------------------------------------;
  168. ; This procedure will read both boot and partition records calculate  ;
  169. ; the check sums (XOR and CHK). These will be recorded on "PARM_FILE".;
  170. ;---------------------------------------------------------------------;
  171. Initialize_all_files:
  172.         CALL    Create_PARM_file          ;Create and open the parameter file
  173.         MOV     DX,offset Init_Msg        ;Explain that we are intializing
  174.         MOV     AH,09H                    ;DOS display string function
  175.         INT     21H
  176.         CALL    Read_Boot_Sector          ;Do actual read of sector 0 (DOS)
  177.  
  178. ;  --------- Calculate cryptographic check/XOR sums for disk sector -----------
  179.         MOV     SI,offset BUFFER          ;Point SI to buffer containing sector
  180.         MOV     CX,Sector_Size            ;Process all bytes in a sector
  181.         CALL    Calc_Sums                 ;Calculate CHK and XOR sums
  182. ; On return:                DI - Contains checksum for this file
  183. ;                           DX - XOR sum
  184. ; -----------------------------------------------------------------------------
  185.  
  186.         MOV     Boot_XOR_Sum,DX           ;Copy XOR sum into PARM buffer
  187.         MOV     SCT_XOR,DX                ;Copy XOR sum to reloadable file
  188.         MOV     Boot_CHK_SUM,DI           ;Copy CHK sum into Parm buffer
  189.         MOV     SCT_CHK,DI                ;Copy CHK sum to reloadable file
  190.         MOV     BYTE PTR[SCT_Type],Boot_type  ;Set sector type indicator to BOOT
  191.         CALL    Write_Boot_Sector         ;Create a reloadable copy of partition
  192.         CALL    Read_Part_Sector          ;Do actual read of sector 0 (BIOS)
  193.         CMP     Partition_wanted,'X'      ;Read failed (no longer wanted)?
  194.         JE      Encrypt_Parm_File         ;  If so, skip writing PARM file
  195.  
  196. ;  --------- Calculate cryptographic check/XOR sums for disk sector -----------
  197.         MOV     SI,offset BUFFER          ;Point SI to buffer containing sector
  198.         MOV     CX,Sector_Size            ;Process all bytes in a sector
  199.         CALL    Calc_Sums                 ;Calculate CHK and XOR sums
  200. ; -----------------------------------------------------------------------------
  201.  
  202.         MOV     Part_XOR_Sum,DX           ;Copy XOR sum into memory
  203.         MOV     SCT_XOR,DX                ;Copy XOR sum to reloadable file
  204.         MOV     Part_CHK_SUM,DI           ;Copy CHK sum into mem
  205.         MOV     SCT_CHK,DI                ;Copy CHK sum to reloadable file
  206.         MOV     BYTE PTR[SCT_Type],PART_type  ;Set sector type indicator to Part
  207.         CALL    Write_Part_Sector         ;Create a reloadable copy of partition
  208. Encrypt_Parm_File:
  209. ;  --------- Calculate cryptographic XOR sum for the PARM file ---------------
  210.         MOV     SI,offset PARM_BUFFER     ;Point SI to buffer containing sector
  211.         MOV     CX,41                     ;Check 1st 41 characters parm_file
  212.         CALL    Calc_Sums                 ;Calculate CHK and XOR sums
  213. ; -----------------------------------------------------------------------------
  214.         MOV     PARM_XOR_Sum,DX           ;Copy XOR sum into memory
  215.         MOV     PARM_CHK_SUM,DI           ;Copy CHK sum into mem
  216.         CALL    Write_Parm_File           ;Write records to parmfile
  217.         MOV     AX,4C10h                  ;DOS terminate with 16 error level
  218.         INT     21h
  219.  
  220.  
  221.  
  222. ;---------------------------------------------------;
  223. ; C O M P A R E    B O O T   S U M S  - any changes?;
  224. ;---------------------------------------------------;
  225. ;Register conventions:                              ;
  226. ;                                                   ;
  227. ; DI - Contains checksum for this file              ;
  228. ; DX - XOR sum                                      ;
  229. ;---------------------------------------------------;
  230. Compare_Boot_Sums:                        ;See if any changes to the sector
  231.         CMP     Boot_XOR_SUM,DX           ;Any change to XOR sum?
  232.         JNE     Boot_change_detected      ;  If not =, report the change
  233.         CMP     BOOT_CHK_SUM,DI           ;Is the checksum OK?
  234.         JNE     Boot_change_detected      ;  If not, report the change
  235.                                           ;  ELSE all is OK with boot sector
  236.         MOV     DX,offset Boot_Msg        ;Display message about boot record
  237.         MOV     AH,09H                    ;DOS display string function
  238.         INT     21H
  239.         MOV     DX,offset OK_Msg          ;Explain that all is well
  240.         MOV     AH,09H                    ;DOS display string function
  241.         INT     21h
  242.         RET
  243.  
  244. Boot_Change_detected:                     ;Report problem with boot record
  245.         ADD     BP,2                      ;Adjust DOS error lvl to ind prblm
  246.         MOV     DX,offset Boot_Msg        ;Display message about boot record
  247.         MOV     AH,09H                    ;DOS display string function
  248.         INT     21H
  249.         MOV     DX,offset Bad_Sector_Msg  ;Explain that its bad
  250.         MOV     AH,09H                    ;DOS display string function
  251.         INT     21H
  252.         CALL    Send_Beep                 ;Wake up user!
  253.         CALL    Wait_For_Key              ;Beep and force user to hit a key
  254.         RET
  255.  
  256. ;---------------------------------------------------;
  257. ; C O M P A R E    P A R T   S U M S  - any changes?;
  258. ;---------------------------------------------------;
  259. ;Register conventions:                              ;
  260. ;                                                   ;
  261. ; DI - Contains checksum for this file              ;
  262. ; DX - XOR sum                                      ;
  263. ;---------------------------------------------------;
  264. Compare_Part_Sums:                        ;See if any changes to the sector
  265.         CMP     Part_XOR_SUM,DX           ;Any change to XOR sum?
  266.         JNE     Part_change_detected      ;  If not =, report the change
  267.         CMP     Part_CHK_SUM,DI           ;Is the checksum OK?
  268.         JNE     Part_change_detected      ;  If not, report the change
  269.                                           ;  ELSE all is OK with Part sector
  270.         MOV     DX,offset Part_Msg        ;Display message about Partition sect
  271.         MOV     AH,09H                    ;DOS display string function
  272.         INT     21H
  273.         MOV     DX,offset OK_Msg          ;Explain that all is well
  274.         MOV     AH,09H                    ;DOS display string function
  275.         INT     21h
  276.         RET
  277.  
  278. Part_Change_detected:                     ;Report problem with Partition sector
  279.         ADD     BP,2                      ;Adjust DOS error lvl to ind prblm
  280.         MOV     DX,offset Part_Msg        ;Display message about Partition sect
  281.         MOV     AH,09H                    ;DOS display string function
  282.         INT     21H
  283.         MOV     DX,offset Bad_Sector_Msg  ;Explain that its bad
  284.         MOV     AH,09H                    ;DOS display string function
  285.         INT     21H
  286.         CALL    Send_Beep                 ;Wake up user!
  287.         CALL    Wait_For_Key              ;Beep and force user to hit a key
  288.         RET
  289.  
  290. ;---------------------------------------------------;
  291. ; R E A D   B O O T   S E C T O R                   ;
  292. ;---------------------------------------------------;
  293. ;Read the DOS boot sector using DOS I/O requests.   ;
  294. ;---------------------------------------------------;
  295. Read_Boot_Sector:
  296.         PUSH    BP                        ;Save all current registers
  297. Try_boot_read_again:                      ;Come here to retry the extended
  298.        ;form of the read if normal int 25h failed. Note, it is NOT an error
  299.        ;that we re-execute the 19h function...some systems require this
  300.         MOV     AH,19h                    ;DOS get current disk drive function
  301.         INT     21h                       ;Get current disk drive in AL (0=A)
  302.         CMP     DOS_Version,4             ;Are we running under DOS 4.x?
  303.         JNE     Old_DOS                   ;If not, do normal int 25 call
  304. ; Process DOS 4.0 disks using extended format of INT25 (handles disks > 32mb)
  305.         MOV     CX,-1                     ;Set indicator to handle >32 mb disks
  306.         MOV     BX,Offset INT25_Parms     ;Point to 10 byte parameter block
  307.         MOV     Buffer_Segment,DS         ;Segment address in parameter block
  308.         JMP     SHORT DOS_Abs_Read        ;Do DOS Absolute sector read
  309. Old_DOS:
  310.         MOV     CX,1                      ;Read just one sector
  311.         XOR     DX,DX                     ;DX=0 to read DOS logical sector 0
  312.         MOV     BX,Offset buffer          ;Place to put the sector
  313. DOS_Abs_Read:
  314.         INT     25h                       ;DOS absolute disk read function
  315.         JNC     Boot_read_OK              ;If I/O was successful
  316.                                           ;Else we had an I/O error
  317. ;
  318. ; Since some OEM versions of DOS such as COMPAQ 3.31 also support the extended
  319. ; format of the int 25h call for disks > 32mb we will lie and say this is
  320. ; DOS 4.x and try the interrupt 4.0 using the extended format call.
  321.         POPF                              ;Remove flags from stack
  322.         CMP     DOS_Version,4             ;Did we already try DOS 4.x type int?
  323.         JE      Boot_Read_Failed          ;  If so, then boot read failed
  324.                                           ;  otherwise try extended int 25h
  325.         MOV     DOS_Version,4             ;  Force extended int 25h use (lie)
  326.         JMP     SHORT Try_Boot_Read_Again ;  do func 19h and then extd int 25h
  327.  
  328. Boot_Read_Failed:
  329.         MOV     DX,offset Boot_Msg        ;Display message about boot record
  330.         MOV     AH,09H                    ;DOS display string function
  331.         INT     21H
  332. Unrecoverable_IO_Error:                   ;Exit here if I/O has failed
  333.         MOV     DX,offset IO_Err_Msg      ;Explain that input/output failed
  334.         MOV     AH,09H                    ;DOS display string function
  335.         INT     21H
  336.         CALL    Send_Beep                 ;Wake up user!
  337.         CALL    Wait_For_Key              ;Beep and force user to hit a key
  338.         MOV     AX,4C40h                  ;   terminate with 64 DOS ERRORLEVEL
  339.         INT     21h
  340. Boot_read_OK:
  341.         POPF                              ;restore flags pushed by INT 25h
  342.         POP     BP                        ;Restore active registers
  343.         RET
  344.  
  345.  
  346. ;---------------------------------------------------;
  347. ; R E A D   P A R T   S E C T O R                   ;
  348. ;---------------------------------------------------;
  349. ;Read the partition sector using BIOS I/O request   ;
  350. ;---------------------------------------------------;
  351. Read_part_Sector:
  352.         MOV     AH,02                     ;BIOS floppy read function of INT 13h
  353.         MOV     DL,BYTE PTR[Drive_number] ;Drive 80 (1st) or 81 (2nd) hard drive
  354.         MOV     AL,1                      ;Read only 1 sector
  355.         MOV     CX,1                      ;Read (CH) track 0, (CL) sector 1
  356.         XOR     DH,DH                     ;Read head number zero
  357.         MOV     BX,Offset buffer          ;Place to put the sector
  358.         INT     13h                       ;BIOS absolute (floppy) disk read
  359.         JNC     Part_Read_OK              ;If I/O was successful
  360.                                           ;Else the we had an I/O error
  361.         MOV     DX,offset No_HardDisk_MSG ;Display message about missing part
  362.         MOV     AH,09H                    ;DOS display string function
  363.         INT     21H
  364.         CMP     Partition_wanted,'Y'      ;Did user ask to read this partition?
  365.         MOV     Partition_wanted,'X'      ;Turn off partn checking (stop write)
  366.         JNE     Part_Read_OK              ;  If user did NOT ask for read,its OK
  367.                                           ;  Otherwise, its a fatal error
  368.         JMP     SHORT Unrecoverable_IO_Error
  369. Part_Read_OK:
  370.         RET
  371.  
  372.  
  373. ;---------------------------------------------------------------------------;
  374. ; Open_and_read_parm_file:                                                  ;
  375. ; Open the parameter(CHKBOOT.PRM) file which contains the cryptographic     ;
  376. ;   XOR and checksums for the boot and partition records.                   ;
  377. ; If Open fails, set a flag to indicate this, (intialize_mode=Y)            ;
  378. ;---------------------------------------------------------------------------;
  379. Open_and_Read_Parm_File:
  380.         MOV     AX,3D00h                  ;Open file for read function
  381.         MOV     DX,offset Parm_File_Name  ;Name of the parameter file:ASCIIZ
  382.         INT     21h                       ;Do open for read
  383.         JNC     File_found                ;If open went OK..
  384.         MOV     Initialize_mode,'Y'       ; If not, force initialization
  385.         MOV     DX,offset Missing_Msg     ;Explain that PARM file is missing
  386.         MOV     AH,09H                    ;DOS display string function
  387.         INT     21H
  388.         CALL    Send_Beep                 ;Wake up user!
  389.         CALL    Wait_For_Key              ;Beep and force user to hit a key
  390.         RET
  391. File_found:
  392.         MOV     BX,AX                     ;File handle in BX
  393.         MOV     CX,45                     ;Read  45 bytes from disk
  394.         MOV     DX,OFFSET PARM_buffer     ;Data to write to disk
  395.         MOV     AH,3FH                    ;DOS read function
  396.         INT     21H                       ;Call DOS
  397.         JNC     Close_Parm_file           ;If no error, continue + close file
  398.         JMP     Bad_Parm_file             ; else Report that we have a bad file
  399. Close_Parm_file:
  400.         MOV     AH,3Eh                    ;DOS close file function code
  401.         INT     21h                       ;Close the file
  402.         RET
  403.  
  404. ;---------------------------------------------------;
  405. ; C R E A T E   P A R M   F I L E                   ;
  406. ; Does an open create/truncate on the "PARM_file"   ;
  407. ; Returns file handle in Parm_handle                ;
  408. ;---------------------------------------------------;
  409. Create_PARM_file:                         ;Create and open the parameter file
  410.         MOV     AH,3Ch                    ;DOS create file function
  411.         MOV     DX,Offset PARM_File_Name
  412.         XOR     CX,CX                     ;Set CX (file attribute=normal) = 0
  413.         INT     21h
  414.         JNC     Create_Parm_Exit          ;IF all went OK then return
  415.         JMP     Unrecoverable_IO_Error
  416. Create_Parm_Exit:
  417.         MOV     Parm_Handle,AX            ;Save file handle
  418.         RET
  419.  
  420. ;---------------------------------------------------;
  421. ; W R I T E    P A R M     F I L E                  ;
  422. ;---------------------------------------------------;
  423. ;Write the parameter file out to disk.              ;
  424. ;This is called only during intialization.          ;
  425. ;---------------------------------------------------;
  426. Write_PARM_File:
  427.         MOV     DX,offset PW_Msg          ;Display message about write parm rec
  428.         MOV     AH,09H                    ;DOS display string function
  429.         INT     21H
  430.         MOV     AH,40h                    ;DOS WRITE function code
  431.         MOV     BX,PARM_Handle            ;Handle for parm_file
  432.         MOV     CX,45                     ;Write 45 bytes to disk
  433.         MOV     DX,OFFSET PARM_buffer     ;Data to write to disk
  434.         INT     21h                       ;Do the I/O
  435.         JNC     PARM_write_OK             ;If I/O was successful
  436.                                           ;Else the we had an I/O error
  437.         JMP     Unrecoverable_IO_Error
  438. PARM_write_OK:                            ;Write of Parm_file worked ok
  439.         MOV     AH,3Eh                    ;DOS close file function code
  440.         INT     21h                       ;Close the file
  441.         RET
  442.  
  443. ;---------------------------------------------------;
  444. ; W R I T E    B O O T   S E C T O R   (F I L E)    ;
  445. ;---------------------------------------------------;
  446. ;Write a reloadable version of the boot sector to   ;
  447. ;DISK. This is done  during intialization.          ;
  448. ;---------------------------------------------------;
  449. Write_Boot_Sector:
  450.         MOV     DX,offset BootW_MSG       ;Display msg about writing boot file
  451.         MOV     AH,09H                    ;DOS display string function
  452.         INT     21H
  453.         MOV     AH,3Ch                    ;DOS create file function
  454.         MOV     DX,Offset Boot_File_Name
  455.         XOR     CX,CX                     ;Set CX (file attribute=normal) = 0
  456.         INT     21h
  457.         JNC     Create_boot_OK            ;IF all went OK then return
  458. Boot_Write_Error:
  459.         JMP     Unrecoverable_IO_Error
  460. Create_Boot_OK:
  461.         MOV     BX,AX                     ;Handle for Boot sector file
  462.         MOV     AH,40h                    ;DOS WRITE function code
  463.         MOV     CX,69                     ;Length of reload sector prefix
  464.         ADD     CX,Sector_Size            ;Write 1 sector + 69 bytes
  465.         MOV     DX,OFFSET Write_buffer    ;Data to write to disk
  466.         INT     21h                       ;Do the I/O
  467.         JNC     Boot_write_OK             ;If I/O was successful
  468.                                           ;Else the we had an I/O error
  469.         JMP     Unrecoverable_IO_Error
  470. Boot_write_OK:                            ;Write of Parm_file worked ok
  471.         MOV     AH,3Eh                    ;DOS close file function code
  472.         INT     21h                       ;Close the file
  473.         RET
  474.  
  475.  
  476. ;---------------------------------------------------;
  477. ; W R I T E    P A R T   S E C T O R   (F I L E)    ;
  478. ;---------------------------------------------------;
  479. ;Write a reloadable version of the partition sector ;
  480. ;to disk. This is done during initialize processing.;
  481. ;---------------------------------------------------;
  482. Write_Part_Sector:
  483.         MOV     DX,offset PartW_MSG       ;Display msg about writing Part file
  484.         MOV     AH,09H                    ;DOS display string function
  485.         INT     21H
  486.         MOV     AH,3Ch                    ;DOS create file function
  487.         MOV     DX,Offset Part_File_Name
  488.         XOR     CX,CX                     ;Set CX (file attribute=normal) = 0
  489.         INT     21h
  490.         JNC     Create_Part_OK            ;IF all went OK then return
  491. Part_Write_Error:
  492.         JMP     Unrecoverable_IO_Error
  493. Create_Part_OK:
  494.         MOV     BX,AX                     ;Handle for Part sector file
  495.         MOV     AH,40h                    ;DOS WRITE function code
  496.         MOV     CX,69                     ;Length of reload sector prefix
  497.         ADD     CX,Sector_Size            ;Write 1 sector + 69 bytes to disk
  498.         MOV     DX,OFFSET Write_buffer    ;Data to write to disk
  499.         INT     21h                       ;Do the I/O
  500.         JNC     Part_write_OK             ;If I/O was successful
  501.                                           ;Else the we had an I/O error
  502.         JMP     Unrecoverable_IO_Error
  503. Part_write_OK:                            ;Write of Parm_file worked ok
  504.         MOV     AH,3Eh                    ;DOS close file function code
  505.         INT     21h                       ;Close the file
  506.         RET
  507.  
  508. ;---------------------------------------------------;
  509. ; V A L I D A T E   P A R M   F I L E               ;
  510. ;---------------------------------------------------;
  511. ;Check that the parameter file itself has not been  ;
  512. ;corrupted in some way.                             ;
  513. ;---------------------------------------------------;
  514. Validate_Parm_File:                       ; make sure its a valid parm file
  515. ;  --------- Calculate cryptographic XOR sum for the PARM file ---------------
  516.         MOV     SI,offset PARM_BUFFER     ;Point SI to buffer containing sector
  517.         MOV     CX,41                     ;Check 1st 41 characters in buffer
  518.         CALL    Calc_Sums                 ;Calculate CHK and XOR sums
  519. ; -----------------------------------------------------------------------------
  520. ;       Compare the calculated with the recorded check/XOR sums
  521.         CMP     PARM_XOR_Sum,DX           ;Compare XOR sum
  522.         JNE     Bad_Parm_File             ;If parm file corrupted..
  523.         CMP     PARM_CHK_SUM,DI           ;Compare CHK sum
  524.         JNE     Bad_Parm_File             ;If parm file corrupted..
  525.         RET                               ;Otherwise return..all is well so far
  526. Bad_Parm_file:
  527.         MOV     DX,offset BadP_MSG        ;Explain that Parm file is corrupted
  528.         MOV     AH,09H                    ;DOS display string function
  529.         INT     21H
  530.         CALL    Send_Beep                 ;Wake up user!
  531.         CALL    Wait_For_Key              ;Beep and force user to hit a key
  532.         MOV     AX,4C20h                  ;   terminate with 32 DOS ERRORLEVEL
  533.         INT     21h
  534.  
  535.  
  536.         SUBTTL  General Purpose subroutines
  537.         PAGE
  538. ;******************************************************************************;
  539. ;**   General purpose subroutines follow                                     **;
  540. ;******************************************************************************;
  541.         SUBTTL  General purpose subroutines
  542.         PAGE
  543. ;---------------------------------------------------;
  544. ; C A L C     S U M S  - Calculate XOR + CHK sums   ;
  545. ;---------------------------------------------------;
  546. ; INPUT:  SI = pointer to file BUFFER to scan       ;
  547. ;         CX = # of characters to read              ;
  548. ;                                                   ;
  549. ;Register conventions:                              ;
  550. ;                                                   ;
  551. ; AL - Each new character read into this register   ;
  552. ; CX - number of chars read in -decreasing counter  ;
  553. ; DI - Contains checksum for this file              ;
  554. ; DX - XOR sum                                      ;
  555. ; SI - index pointing into file BUFFER              ;
  556. ; --------------------------------------------------;
  557. Calc_Sums:
  558.         XOR     DX,DX                     ;Zero XOR sum
  559.         XOR     DI,DI                     ;Zero CHK sum
  560.         XOR     AH,AH                     ;Zero upper part of AX for addition
  561.  
  562. ; Innermost  char loop  - keep this fast!
  563. NEXT_CHAR:
  564.         LODSB                             ;Get char into AL
  565.         XOR     DL,AL                     ;cumulative XOR into DX
  566.         ROL     DX,1                      ;Keep shifting to XOR sum to left
  567.         ADD     DI,AX                     ;cumulative check sum
  568.         LOOP    NEXT_CHAR                 ;CONTINUE SCANNING CHARS UNTIL EOB
  569.         RET                               ;All done calculating sums!
  570.  
  571.  
  572. ;---------------------------------------------------;
  573. ; D I S P L A Y   M A X   H E L P - Display adv help;
  574. ;---------------------------------------------------;
  575. ; 1) Clear the screen                               ;
  576. ; 2) Send message pointed to by DS:DX               ;
  577. ; 3) Beep and wait for any key press                ;
  578. ; --------------------------------------------------;
  579. Display_Max_Help:
  580.         CALL    Clear_Screen              ;Clear screen and set cursor to top
  581.         MOV     AH,09H                    ;DOS display string function
  582.         INT     21H
  583.         CALL    Pos_Cursor_Line25         ;Go to last line of screen
  584.         CALL    Wait_for_key              ;Wait for key press
  585.         RET
  586.  
  587. ;---------------------------------------------------;
  588. ; C L E A R   S C R E E N - Erase contents of screen;
  589. ;  and position cursor at top of screen. Maintain   ;
  590. ;  user's current screen attributes (colors).       ;
  591. ;                                                   ;
  592. ; Entry: Current_Screen_atr contains current screen ;
  593. ;        attribute. (Set by routine: Get_Screen_Atr);
  594. ;---------------------------------------------------;
  595. Clear_Screen:
  596.         PUSH    BP                        ;Save registers
  597.         PUSH    DX
  598. ; Clear the screen using the BIOS scroll screen function
  599.         MOV     AX,0600h                  ;06=scroll function.
  600.                                           ;00=lines to scroll = clear screen
  601.         MOV     BH,Current_Screen_Atr     ;Attribute byte to fill screen
  602.         MOV     CX,00                     ;upper left corner is (0,0) = (y,x)
  603.         MOV     DX,184Fh                  ;Lower rt corner=(y,x)=(24,79)
  604.         INT     10h                       ;Call BIOS video services
  605. ; Position cursor to line 00 column 00
  606.         MOV     AH,02                     ;BIOS int 10h set cursor position func
  607.         XOR     BH,BH                     ;Set page to zero
  608.         MOV     DX,0000h                  ;Set cusor to row 00 and column 00
  609.         INT     10h                       ;BIOS video services
  610.         POP     DX
  611.         POP     BP                        ;Restore registers
  612.         RET
  613.  
  614.  
  615. ;---------------------------------------------------;
  616. ; S E N D   B E E P                                 ;
  617. ;---------------------------------------------------;
  618. ; Cause the PC to put out a BEEP sound.             ;
  619. ;This is used to alert user to an error condition.  ;
  620. ;---------------------------------------------------;
  621. Send_Beep:
  622.         PUSH    BP                        ;Save all vulnarable registers
  623.         PUSH    DX
  624. ; Produce a beep to alert the user:  (use  BIOS TTY func to write an ASCII BELL)
  625.         MOV     AX,0E07H                  ;BIOS func (0Eh) to write (07H) beep
  626.         XOR     BH,BH                     ;Select page zero for output
  627.         INT     10H                       ;BIOS video function (0Eh=write char)
  628.         POP     DX
  629.         POP     BP                        ;Restore registers
  630.         RET
  631.  
  632. ;---------------------------------------------------;
  633. ; G E T   C U R R E N T    S C R E E N  A T R ribute;
  634. ;---------------------------------------------------;
  635. ;Determine forground and background colors in use   ;
  636. ;and save for use by other BIOS video functions.    ;
  637. ;  Save it in:   "Current_Screen_Atr"               ;
  638. ;---------------------------------------------------;
  639. Get_Current_Screen_Atr:
  640.         PUSH    BP                        ;Save all vulnarable registers
  641.         PUSH    DX
  642. ;Find out what attribute is being used for display
  643.         MOV     AH,08h                    ;read attrib + char function
  644.         INT     10h                       ;Call BIOS video services
  645.         MOV     Current_Screen_Atr,AH     ;Save AH=attribute byte
  646.         POP     DX
  647.         POP     BP                        ;Restore registers
  648.         RET
  649.  
  650. ;---------------------------------------------------;
  651. ; P O S   C U R S O R  on  L I N E 2 5              ;
  652. ;---------------------------------------------------;
  653. ;Move cursor position to line 25 (BIOS line 24)     ;
  654. ;the last line on the screen.                  .    ;
  655. ;---------------------------------------------------;
  656. Pos_Cursor_Line25:
  657.         PUSH    BP                        ;Save all vulnarable registers
  658.         PUSH    DX
  659. ; Position cursor to line 25 and column 01: (TO BIOS col 00 + row 24)
  660.         MOV     AH,02                     ;BIOS int 10h set cursor position func
  661.         XOR     BH,BH                     ;Set page to zero
  662.         MOV     DX,1800h                  ;DH = row 24; DL = col 00
  663.         INT     10h                       ;BIOS video services
  664.         POP     DX
  665.         POP     BP                        ;Restore registers
  666.         RET
  667.  
  668. ;---------------------------------------------------;
  669. ; W A I T   F O R   K E Y                           ;
  670. ;---------------------------------------------------;
  671. ; 1) Put out message to hit any key on current line.;
  672. ; 2) Wait for any key press                         ;
  673. ; 3) Erase message using current screen attribute   ;
  674. ; 4) Position currsor back at start of current line.;
  675. ; --------------------------------------------------;
  676. Wait_For_Key:
  677.         PUSH    BP                        ;Save all corrupted registers
  678.         PUSH    DX
  679.  
  680. ;Find out what line the cursor is on
  681.         MOV     AH,03h                    ;Read cursor position function
  682.         INT     10h                       ;BIOS video services
  683.         PUSH    DX                        ;DH contains row (line #) Save it!
  684.  
  685. ; Position cursor to current line + column 28: (TO BIOS  row 27)
  686.         MOV     AH,02                     ;BIOS int 10h set cursor position func
  687.         XOR     BH,BH                     ;Set page to zero
  688.                                           ;DH contains current row
  689.         MOV     DL,1Bh                    ;Set cusor current row and col 27
  690.         INT     10h                       ;BIOS video services
  691.  
  692. ; Put -Hit any key- message out with inverse video attribute type on
  693. ;       XOR     BH,BH                     ;Set page to zero  (BH is still 0)
  694.         MOV     BL,0F0h                   ;Inverse video attribute
  695.         MOV     CX,1                      ;Character count
  696.         MOV     SI,offset Hit_Key_Msg     ;The hit-any-key message
  697. Display_next_video_char:
  698.         MOV     AH,09H                    ;BIOS int 10h write attrib + char func
  699.         LODSB                             ;Get next character for output
  700.         PUSH    SI                        ;Save SI (int 10h may corrupt it)
  701.         INT     10h                       ;Put character and attribute out
  702.         INC     DX                        ;Advance cursor position
  703.         MOV     AH,02                     ;Adv cursor function
  704.         INT     10h                       ;   advance the cursor (BIOS)
  705.         POP     SI                        ;Restore saved SI
  706.         CMP     SI,offset Hit_key_Msg_end ;are we at end of message?
  707.         JB      Display_next_video_char   ;  If not get next char for display
  708.                                           ;  Else, wait for key press by user
  709. ; Wait for user to hit any key
  710.         XOR     AX,AX
  711.         INT     16h                       ;Wait for user to hit a key
  712.  
  713. ; Erase HIT ANY KEY message
  714.         POP     DX                        ;DH=current line number
  715.         MOV     BH,Current_Screen_Atr     ;AH=user's screen attribute
  716.         MOV     AH,06h                    ;INIT window function
  717.         XOR     AL,AL                     ;Zero AL to clear window
  718.         MOV     CH,DH                     ;Current row (y coor upr lft)
  719.         MOV     CL,00                     ;Start in first char position
  720.         MOV     DL,79                     ;Last char pos - blank entire line
  721.         INT     10h                       ;Blank out line
  722.  
  723. ; Position cursor to start of blanked line
  724.         MOV     AH,02                     ;BIOS int 10h set cursor position func
  725.         XOR     DL,DL                     ;DH=cur line, DL=0: first char pos
  726.         XOR     BX,BX                     ;Use video page zero
  727.         INT     10h                       ;BIOS video services
  728.  
  729.         POP     DX
  730.         POP     BP
  731.         RET                               ;Return to caller
  732.  
  733.  
  734. ; ----------------------------------------------------------------------------;
  735. ; Initialization code - parse parms + put out msgs                            ;
  736. ; ----------------------------------------------------------------------------;
  737. Parse_parms:                              ;Parse input parameters
  738.         MOV     AH,30h                    ;Check DOS version
  739.         INT     21h                       ;    Ask DOS: "who are you?"
  740.         OR      AL,AL                     ;Check if before DOS 2.x (AL=0)
  741.         JNE     DOS_is_OK                 ;If good DOS vers, then continue
  742.         MOV     DX, OFFSET Bad_DOS_Msg    ;   ELSE  Send MSG that
  743.         MOV     AH,09h                    ;   DOS version is too low.
  744.         INT     21h
  745.         INT     20h                       ;  Old style DOS terminate interupt
  746. DOS_is_OK:
  747.         MOV     DOS_Version,AL            ;Save major DOS version number (0-4)
  748.         MOV     SI,80H                    ;Parameter area in PSP
  749.         MOV     CL,[SI]                   ;Get # of chars in input parm
  750.         XOR     CH,CH                     ;CLEAR UPPER BYTE OF CHR COUNT
  751.         OR      CL,CL                     ;CHECK FOR 0 CHARS (NO INPUT)
  752.         MOV     DX, OFFSET Explanation    ;Give user full explanation of prgm
  753.         JNZ     Continue_parse            ;If some parameters keep going
  754.         JMP     Help_display              ; Else, give user some help info
  755. Continue_parse:
  756.         INC     SI                        ;POINT TO FIRST CHARACTER
  757.         CLD                               ;FORWARD DIRECTION
  758.  
  759. DEL_SPACES:
  760.         LODSB                             ;Get byte at DS:SI and inc SI
  761.         CMP     AL,'/'                    ;Is it a "/"
  762.         JE      Scan_for_parms            ;If so, we have a parameter
  763.         CMP     AL,' '                    ;Is it a space?
  764.         JNE     Scan_Filespec             ;If not we have a filespec
  765.         LOOP    DEL_SPACES                ;CONT CHECKING UNTIL LAST CHAR
  766.         JMP     Help_Display
  767.  
  768. ;---------------------------------------------------------------------------;
  769. ; Conventions for command line parsing:                                     ;
  770. ;   SI points to next char to be checked in the parm field at DS:80         ;
  771. ;   CX is count of characters left to be scanned                            ;
  772. ;---------------------------------------------------------------------------;
  773.  
  774. Scan_Filespec:                            ;Parse user override to parameter file
  775. ;----------------------------------------;
  776. ; Parse filespec + xfer to Parm_FIle_Name;
  777. ;----------------------------------------;
  778.         DEC     SI                        ;point back to 1ST letter of filespec
  779.         MOV     DI, offset Parm_File_Name ;prep to transfer file name to msg
  780.  
  781. Scan_To_File_Spec_End:
  782. ;       start scanning the file specification and transfer into output field
  783.         LODSB                             ;Get next char of file spec
  784.         CMP     AL,' '                    ;check valid separator character
  785.         JBE     file_spec_end_found
  786.         CMP     AL,'/'                    ;check for valid separator
  787.         JE      file_spec_end_found
  788.         STOSB                             ;Store char as part of User_file_spec
  789.         LOOP    Scan_To_File_Spec_End
  790.         JMP     Help_Display              ;There must be at least on /x parm
  791.                                           ;So give user HELP with CHKBOOT
  792.  
  793. File_Spec_End_Found:
  794.                                           ;SI = next char loc after filespec
  795.         PUSH    AX                        ;Save last char examined
  796.         MOV     AL,00                     ;Zero terminate the filespec
  797.         STOSB                             ;  combination as a single word
  798.         POP     AX                        ;Restore last character examined
  799.  
  800. Scan_for_parms:
  801.         CMP     CX,01                     ;Check if we out of chars to scan
  802.         JA      Parm_Scan                 ;If some are left, check parameters
  803.         JMP     Help_display              ;If so, user needs HELP
  804.  
  805. Check_parm_chars_left:                    ;Check if enough chars left for a parm
  806.         CMP     CX,01                     ;Check if we out of chars to scan
  807.         JA      Parm_Scan                 ;  if not continue chcking for /parms
  808.         RET                               ;  If so, return
  809. Parm_Scan:                                ;Check for presence of a /_ parm
  810.         CMP     AL,'/'                    ;check for "/" parm character
  811.         JE      Parm_found
  812.         CMP     AL,' '                    ;check for blanks
  813.         JNE     Unrecog_parm              ;If other than blank its illegal...
  814.         LODSB                             ;Keep checking next character
  815.         LOOP    Parm_Scan
  816.         RET                               ;All done
  817.  
  818. Parm_Found:                               ;Check if parm is valid
  819.         DEC     CX                        ;Adjust chars remaining counter
  820.         JCXZ    Unrecog_parm              ;IF no chars left then parm is invalid
  821.         LODSB                             ;Get next char
  822.         DEC     CX                        ;Adjust chars remaining counter
  823.         CMP     AL,'2'                    ;Is it the Initialize parm?
  824.         JE      Two_parm                  ;2 parm detected..
  825.         AND     AL,5Fh                    ;Capitalize char
  826.         CMP     AL,'P'                    ;Is it Partition table parm?
  827.         JE      P_parm                    ;P parameter detected
  828.         CMP     AL,'B'                    ;Is it the Boot record parm?
  829.         JE      B_parm                    ;I parm detected..
  830.         CMP     AL,'I'                    ;Is it the Initialize parm?
  831.         JE      I_parm                    ;I parm detected..
  832.         CMP     AL,'H'                    ;Is it the Initialize parm?
  833.         JE      H_parm                    ;I parm detected..
  834. Unrecog_parm:                             ; an illegal paramter:
  835.         MOV     DX, offset Bad_Parm_Msg   ;indicate illegal parm was found
  836.         MOV     AH,09H                    ;DOS display string function
  837.         INT     21H
  838.         JMP     SHORT ERR_Exit            ;terminate with error level set
  839.  
  840. Illegal_P_2_Parms:                        ;User has entered both /P + /2
  841.         MOV     DX, offset Bad_P_2_Msg    ;indicate use of /P+/2 found
  842.         MOV     AH,09H                    ;DOS display string function
  843.         INT     21H
  844.         JMP     SHORT ERR_Exit            ;terminate with error level set
  845.  
  846. P_parm:
  847.         CMP     Partition2_wanted,'Y'     ;Has user already selected /2
  848.         JE      Illegal_P_2_Parms         ;  If so, give error message
  849.         MOV     Partition_wanted,'Y'      ;Indicate user wants partition table
  850.         LODSB                             ;Keep checking next character
  851.         JMP     SHORT Check_Parm_chars_left     ;Check for additional parms
  852.  
  853. B_parm:
  854.         MOV     Boot_wanted,'Y'           ;Indicate user wants boot record
  855.         LODSB                             ;Keep checking next character
  856.         JMP     SHORT Check_Parm_chars_left     ;Check for additional parms
  857.  
  858. I_parm:
  859.         MOV     Initialize_mode,'Y'       ;Force intialization mode
  860.         LODSB                             ;Keep checking next character
  861.         JMP     SHORT Check_Parm_chars_left     ;Check for additional parms
  862.  
  863. Two_parm:                                 ;/2 parm (read partition on 2nd disk)
  864.         CMP     Partition_wanted,'Y'      ;Has user already selected /P
  865.         JE      Illegal_P_2_Parms         ;  If so, give error message
  866.         MOV     Partition_wanted,'Y'      ;Indicate user wants a partition table
  867.         MOV     Partition2_wanted,'Y'     ;Indicate user wants 2nd partit table
  868.         INC     Drive_number              ;Read drive number 81 (2nd hard drive)
  869.         LODSB                             ;Keep checking next character
  870.         JMP     SHORT Check_Parm_chars_left     ;Check for additional parms
  871.  
  872. H_parm:                                   ;Handle HELP request
  873.         CALL    Get_Current_Screen_Atr    ;Use user's choice of screen colors
  874.         MOV     DX, offset Max_Help1      ;Give user detailed help information
  875.         CALL    Display_Max_Help          ;Clear screen/Displ HELP/wait for key
  876.         MOV     DX, offset Max_Help2      ;Give user Help page 2
  877.         CALL    Display_Max_Help
  878.         MOV     DX, offset Max_Help3      ;Help page 3
  879.         CALL    Display_Max_Help
  880.         CALL    Clear_Screen
  881.         JMP     SHORT Syntax_msg_only     ;Give syntax summary
  882.  
  883. Err_Exit:
  884.         CALL    Send_Beep                 ;Alert user to serious error!
  885.         CALL    Wait_For_Key              ;Beep and force user to hit a key
  886. Syntax_msg_only:
  887.         MOV     DX, offset Syntax_Msg     ;show user correct syntax
  888. Help_Display:
  889.         MOV     AH,09H                    ;DOS display string function
  890.         INT     21H
  891.         MOV     AX,4C80h                  ;   terminate with 128 DOS ERRORLEVEL
  892.         INT     21h
  893.  
  894.  
  895.  
  896.         SUBTTL  Definition of Data structures
  897.         PAGE
  898. ;******************************************************************************;
  899. ;**   Definition of Data areas follow                                        **;
  900. ;******************************************************************************;
  901. Boot_wanted         DB 'N'                ;Read DOS boot sector Y or N?
  902. partition_wanted    DB 'N'                ;Read any Partition sector Y or N?
  903. partition2_wanted   DB 'N'                ;Read part on 2nd disk Y or N?
  904. Initialize_Mode     DB 'N'                ;Read DOS boot sector Y or N?
  905. Current_Screen_Atr  DB 07                 ;Screen attribute to use for BIOS I/O
  906. DOS_Version         DB 00                 ;Major version of DOS used (0 - 4)
  907. Sector_Size         DW 00                 ;Number of bytes per sector
  908.  
  909. INT25_Parms         LABEL BYTE            ;DOS 4.0 INT25/26 parameter block
  910. Sector_Number       DD  00                ;DOS logical sector number to read
  911. Sector_Count        DW  01                ;Read 1 sector
  912. Buffer_Offset       DW  OFFSET Buffer     ;Buffer address - offset
  913. Buffer_Segment      DW  0                 ;  segment - set at run time
  914.  
  915. Missing_Msg    DB  'Parameter file is missing. Creating a new copy...',CR,LF,'$'
  916. PW_MSG         DB  'Writing the parameter file.',CR,LF,'$'
  917. BootW_MSG      DB  'Writing "@@BOOT.SCT."',CR,LF,'$'
  918. PartW_MSG      DB  'Writing "@@PARTIT.SCT".',CR,LF,'$'
  919. Init_Msg       DB  'Executing in initialization mode. New files will be '
  920.                DB   'created. (.PRM + .SCT)',CR,LF,'$'
  921. IO_ERR_Msg     DB  'I/O error',CR,LF,'$'
  922. No_hardDisk_MSG DB  'Partition sector not processed. Hard disk not found.'
  923.                DB   CR,LF,'$'
  924. BAD_Sector_Msg DB 'modification (system corruption) detected.',CR,LF,'$'
  925. BadP_MSG       DB 'Parameter file has been corrupted.',CR,LF,'$'
  926.                DB   CR,LF,'$'
  927. Part_Msg       DB  'Partition sector ','$'
  928. Boot_Msg       DB  'DOS Boot sector ','$'
  929. OK_Msg         DB  'OK.',CR,LF,'$'
  930. Parm_File_name DB 'CHKBOOT.PRM'           ;ASCIIZ string of parameter file name
  931.                DB 64 DUP (0)              ;Include space to handle path on file
  932. Boot_File_name DB '@@BOOT.SCT',00         ;ASCIIZ string of boot sector file
  933. Part_File_name DB '@@PARTIT.SCT',00       ;ASCIIZ string of partition file
  934. Drive_number   DW  80h                    ;Drive number for BIOS hard disk read
  935. Parm_handle    DW  00h                    ;File handle for parameter file
  936. Parm_Buffer    Label byte
  937. Parm_header    DB 'CHKBOOT-Author: Wolfgang Stiller:'
  938. Boot_XOR_Sum   DW   0000h                 ;Boot record exclusive or sum
  939. Boot_CHK_Sum   DW   0000h                 ;Boot record check sum
  940. Part_XOR_Sum   DW   0000h                 ;Partition record exclusive or sum
  941. Part_CHK_Sum   DW   0000h                 ;Partition record check sum
  942. PARM_XOR_Sum   DW   0000h                 ;Validity check for PARM_file itself
  943. PARM_CHK_Sum   DW   0000h                 ;Validity check for PARM_file itself
  944. Hit_Key_MSG    DB   '-Hit any key-'
  945. Hit_Key_MSG_end EQU $
  946.  
  947. Explanation   LABEL BYTE
  948.   DB  'CHKBOOT will check the DOS boot record and/or the partition sector for '
  949.   DB   'any ',CR,LF
  950.   DB  'changes by using information recorded on the parameter file.  On first'
  951.   DB   CR,LF
  952.   DB  'execution, or with the "/I" parameter, CHKBOOT writes cryptographic '
  953.   DB   'check',CR,LF
  954.   DB  'values to the parameter file and creates reload files for the boot '
  955.   DB   'and',CR,LF
  956.   DB  'partition sectors. All files written contain self check information.'
  957.   DB  CR,LF,LF
  958.  
  959. Syntax_Msg    LABEL  BYTE
  960.   DB  'Syntax is: CHKBOOT [filespec] [/B] [/H] [/I] [/P] [/2]',CR,LF
  961.   DB  '"filespec" is optional file specification for the parameter file. If not'
  962.   DB  CR,LF
  963.   DB  '       specified, "CHKBOOT.PRM" will be used as the parameter file.'
  964.   DB  CR,LF
  965.   DB  ' "/H"  Presents extensive detailed Help information.',CR,LF
  966.   DB  ' "/B"  Checks boot record on current DOS disk for any changes.',CR,LF
  967.   DB  ' "/P"  Checks partition sector on first physical hard disk for any '
  968.   DB  'changes.',CR,LF
  969.   DB  ' "/2"  Checks partition sector on second physical hard disk.'
  970.   DB  CR,LF
  971.   DB  '       /P and /2 may not be specified together.'
  972.   DB  CR,LF
  973.   DB  ' "/I"  Force initialization. Attempts read of current boot sector and '
  974.   DB  'partition',CR,LF
  975.   DB  '       sector on 1st hard drive (Include /2 for 2nd partition sector). '
  976.   DB  'CHKBOOT',CR,LF
  977.   DB  '       then writes the parameter file so that any changes to these '
  978.   DB  'sectors can',CR,LF
  979.   DB  '       be detected on subsequent executions. The boot and partition '
  980.   DB  'sectors are',CR,LF
  981.   DB  '       copied to files: "@@BOOT.SCT" and "@@PARTIT.SCT"  for "LODboot" '
  982.   DB  'reload.',CR,LF
  983.  
  984. Header_msg    LABEL  BYTE
  985.   DB UPLT_Corner,76 DUP(Horizontal),UPRT_Corner,CR,LF
  986.   DB vertical,"  CHKBOOT 1.0 ■ PCDATA TOOLKIT Copyright (c) 1990 Ziff "
  987.   DB "Communications Co.   ",vertical,CR,LF
  988.   DB Vertical,"                     PC Magazine ■ Wolfgang Stiller    "
  989.   DB "                     ",vertical,CR,LF
  990.   DB LWLT_Corner,76 DUP(Horizontal),LWRT_Corner,CR,LF,'$'
  991.  
  992. Write_Buffer  DB  'LODboot reload file. Copy me to a floppy.'
  993.               DB  'By Wolfgang Stiller',CR,LF
  994.               DW  0FFFFh                  ;Special boot/partition indicator
  995. SCT_TYPE      DB  0FFh                    ;Indicate if this is boot or part rec
  996.                                           ; FF=Boot and 55=Partition sector
  997. SCT_CHK       DW  00h                     ;CHK SUM(boot when used for parm file
  998. SCT_XOR       DW  00h                     ;XOR SUM
  999. Buffer        label  byte                 ;All storage + code following is in
  1000.                                           ; the input file buffer.
  1001. Bad_P_2_Msg    DB  '***SORRY***, /P may not be used with /2.',cr,lf,lf,'$'
  1002. Bad_Parm_Msg   DB  'Unrecognized parameter detected.',cr,lf,'$'
  1003. Bad_DOS_MSG    DB  'DOS 2.x or higher required.',CR,LF,'$'
  1004. Non_Std_Msg    DB  'Note, sectors on this disk are not 512 bytes.',CR,LF,'$'
  1005. Max_Help1 DB  'The most difficult to detect type of damage (such as virus '
  1006.   DB  'infection) is',CR,LF
  1007.   DB  'corruption of either your DOS boot sector or the partition sector. '
  1008.   DB  'CHKBOOT',CR,LF
  1009.   DB  'will detect such damage if it happens, and give you the means to fix it'
  1010.   DB  CR,LF
  1011.   DB  'with program LODboot.'
  1012.   DB  CR,LF,LF
  1013.   DB  'What is a boot sector?'
  1014.   DB  CR,LF
  1015.   DB  'The boot sector is sector 0 on a bootable DOS disk(ette).  This sector '
  1016.   DB  'contains',CR,LF
  1017.   DB  'the initial program executed when DOS is first started or booted by '
  1018.   DB  'the ',CR,LF
  1019.   DB  'CNTL/ALT/DEL key combination. If this sector is damaged, you will have'
  1020.   DB  CR,LF
  1021.   DB  'an unreliable or non-functioning operating system.'
  1022.   DB  CR,LF,LF
  1023.   DB  'What is a partition sector (AKA: partition table)?'
  1024.   DB  CR,LF
  1025.   DB  'If you have a hard (fixed) disk, each physical disk drive can be '
  1026.   DB  'partitioned',CR,LF
  1027.   DB  'into multiple logical disks. A table on the first sector of the disk '
  1028.   DB  'contains',CR,LF
  1029.   DB  'information on how the disk is partitioned.  If the hard disk is '
  1030.   DB  'bootable, then',CR,LF
  1031.   DB  'the partition sector also contains a program that loads and executes '
  1032.   DB  'the DOS',CR,LF
  1033.   DB  'boot sector. If the partition sector is damaged, your hard disk '
  1034.   DB  'may be unusable.$'
  1035. Max_Help2  DB  'What does CHKBOOT do?'
  1036.      DB  CR,LF,LF
  1037.      DB  '1)During initialization, it will read the boot record on '
  1038.      DB  'the current disk and',CR,LF
  1039.      DB  '  attempt to read the partition record on the first hard disk ('
  1040.      DB  'or the second',CR,LF
  1041.      DB  '  hard disk if "/2" is specified). Copies of these sectors will '
  1042.      DB  'be written to',CR,LF
  1043.      DB  '  files: @@BOOT.SCT and @@PARTIT.SCT. CHKBOOT will use 2 '
  1044.      DB  'different algorithms',CR,LF
  1045.      DB  '  to compute 32 bit cryptographic check signatures which uniquely '
  1046.      DB  CR,LF
  1047.      DB  '  characterize each sector. These cryptographic signatures will '
  1048.      DB  'be further',CR,LF
  1049.      DB  '  encrypted and recorded on the parameter file.'
  1050.      DB  CR,LF,LF
  1051.      DB  '2)In normal use, CHKBOOT will read the parameter file and verify '
  1052.      DB  'its integrity.',CR,LF
  1053.      DB  '  It will then read the boot and/or the partition sectors. '
  1054.      DB  'The cryptographic',CR,LF
  1055.      DB  '  signatures will be calculated and compared with information '
  1056.      DB  'stored on the',CR,LF
  1057.      DB  '  parameter file. If a change to the boot or partition sectors '
  1058.      DB  'is detected,',CR,LF
  1059.      DB  '  the user will be notified.'
  1060.      DB  '$'
  1061. Max_Help3 DB  'How do you use CHKBOOT?'
  1062.      DB  CR,LF,LF
  1063.      DB  '1) Enter "CHKBOOT /I", in the root directory on any disks from '
  1064.      DB  'which you boot',CR,LF
  1065.      DB  '   your PC. This forces initialization of the parameter file '
  1066.      DB '("CHKBOOT.PRM")',CR,LF
  1067.      DB  '   and creates copies of the boot and partition sectors. If you '
  1068.      DB  'boot from your',CR,LF
  1069.      DB  '   second hard disk, enter: "CHKBOOT /I/2".'
  1070.      DB  CR,LF,LF
  1071.      DB  '2) Create a bootable floppy (FORMAT A:/S), then copy '
  1072.      DB  '@@BOOT.SCT, @@PARTIT.SCT,',CR,LF
  1073.      DB  '   CHKBOOT.PRM, CHKBOOT.COM and LODBOOT.COM to it.',CR,LF,LF
  1074.      DB  '3) Modify your AUTOEXEC.BAT file to include:'
  1075.      DB  CR,LF
  1076.      DB  '   "CHKBOOT /B" - for floppy only systems or'
  1077.      DB  CR,LF
  1078.      DB  '   "CHKBOOT /B/P" for systems where you boot from the first '
  1079.      DB  'hard drive or',CR,LF
  1080.      DB  '   "CHKBOOT /B/2" for systems where you boot from hard drive #2.'
  1081.      DB  CR,LF
  1082.      DB  '   If any changes are detected, CHKBOOT will beep, display a '
  1083.      DB  'message and wait',CR,LF
  1084.      DB  '   for a key press. Program LODboot can be used to restore.'
  1085.      DB  CR,LF,LF
  1086.      DB  '4) Checking in the AUTOEXEC file may not be effective if a '
  1087.      DB  'virus is already in',CR,LF
  1088.      DB  '   control, so also periodically issue the above command '
  1089.      DB  'after booting from',CR,LF
  1090.      DB  '   the floppy created in step 2 above.  For example, on the disk'
  1091.      DB  ' being checked,'
  1092.      DB  CR,LF
  1093.      DB  '   type:',CR,LF
  1094.      DB  '                  "a:CHKBOOT a:CHKBOOT.PRM/B/P"',CR,LF
  1095.      DB  '   where "a:" is the floppy drive with the .PRM file.'
  1096.      DB  '$'
  1097. CSEG    EndS
  1098.         END     CHKBOOT
  1099.